home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / QUIZGAM.DIR / 00178_Script_INITIALIZE HANDLERS < prev    next >
Text File  |  1996-03-19  |  7KB  |  219 lines

  1. -- -----------------------------------------------------------------------------
  2. -- handler startMovie
  3.  
  4. on startMovie
  5.   global spriteNrOfFirstTileOffset,spriteNrOfLastTile
  6.   
  7.   setAuxiliarySearch
  8.   setSpritesVisibility (spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,TRUE
  9.   
  10. end
  11.  
  12.  
  13. -- -----------------------------------------------------------------------------
  14. -- handler stopMovie
  15.  
  16. on stopMovie
  17.   global spriteNrOfFirstTileOffset,spriteNrOfLastTile
  18.   
  19.   setSpritesVisibility (spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,TRUE
  20.   showBackgroundTiles
  21.   
  22. end
  23.  
  24.  
  25. -- -----------------------------------------------------------------------------
  26. -- handler initializeLeoGame
  27.  
  28. on initializeLeoGame
  29.   global nrOfQuestionsPerTile,nrOfTiles,spriteNrOfFirstTileOffset,spriteNrOfLastTile
  30.   global questionIndex,waitFeedback,wrongAnswer,gameOverSound
  31.   global gameNr,QCastName,ACastName,answers,soundFolder,buttonHeight
  32.   global backgroundTileOffset,coloredTileOffset,soundHolder,feedBackSprite
  33.   
  34.   -- 1 VARIABLE INITIALIZING
  35.   
  36.   -- set the number of questions per tile,number of tiles
  37.   set nrOfQuestionsPerTile      = 3
  38.   set backgroundTileOffset      = 29
  39.   set nrOfTiles                 = 9
  40.   set coloredTileOffset         = 1
  41.   set spriteNrOfFirstTileOffset = 10
  42.   set spriteNrOfLastTile        = spriteNrOfFirstTileOffset + (2 * nrOfTiles)
  43.   set feedBackSprite            = 29
  44.   
  45.   -- IMPORTANT for handler showNextQuestionForTile
  46.   
  47.   
  48.   -- names of soundfiles
  49.   set wrongAnswer                = "Wrong.aif"
  50.   set soundHolder                = "soundHolder"
  51.   
  52.   -- the name of the soundfolder...
  53.   set soundFolder                = the pathName & "quizGamA"
  54.   
  55.   -- need to know this in handler "getAnswerClicked"
  56.   set buttonHeight               = the height of cast "oneButton"
  57.   
  58.   -- contains correct answers for questions
  59.   set answers                    = field "answers"
  60.   
  61.   -- name of castmembers with question,answer
  62.   set QCastName                  = "Q"
  63.   set ACastName                  = "A"
  64.   
  65.   -- the position of the pointer to the next question in field questionNumbers
  66.   set questionIndex              = nrOfQuestionsPerTile + 1
  67.   
  68.   -- indicates the nr of the game we're starting with
  69.   set gameNr                     = 1
  70.   
  71.   -- 2 HANDLERCALLS
  72.   
  73.   -- make the background picture tiles invisible
  74.   hideBackgroundTiles
  75.   
  76.   --  set the puppets of Q & A sprites AND the sprites containing coloredTiles
  77.   setQuestionPuppets TRUE
  78.   setColoredTilePuppets TRUE
  79.   
  80.   -- set the stretch of the sprites containing coloredTiles to false
  81.   setQuestionStretch FALSE
  82.   setColoredTileStretch FALSE
  83.   
  84. end
  85.  
  86.  
  87. -- -----------------------------------------------------------------------------
  88. -- handler setQuestionPuppets sets the puppets of sprites containing Q and A
  89.  
  90. on setQuestionPuppets state
  91.   global spriteNrOfFirstTileOffset,spriteNrOfLastTile
  92.   
  93.   setPuppets(spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,state
  94.   
  95. end
  96.  
  97. -- -----------------------------------------------------------------------------
  98. -- handler setColoredTilePuppets sets the puppets of sprites containing colored tiles
  99.  
  100. on setColoredTilePuppets state
  101.   global coloredTileOffset,nrOfTiles
  102.   
  103.   setPuppets (coloredTileOffset + 1),(coloredTileOffset + nrOfTiles),state
  104.   
  105. end
  106.  
  107.  
  108. -- -----------------------------------------------------------------------------
  109. -- handler setQuestionStretch sets the stretch of sprites containing Q and A
  110.  
  111. on setQuestionStretch state
  112.   global spriteNrOfFirstTileOffset,spriteNrOfLastTile
  113.   
  114.   setStretch (spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,state
  115.   
  116. end
  117.  
  118.  
  119. -- -----------------------------------------------------------------------------
  120. -- handler setColoredTileStretch sets the stretch of sprites containing colored tiles
  121.  
  122. on setColoredTileStretch state
  123.   global coloredTileOffset,nrOfTiles
  124.   
  125.   setStretch (coloredTileOffset + 1),(coloredTileOffset + nrOfTiles),state
  126.   
  127. end
  128.  
  129.  
  130. -- -----------------------------------------------------------------------------
  131. -- handler hideBackgroundTiles hides the tiled picture that gets revealed by answering
  132. -- questions
  133.  
  134. on hideBackgroundTiles
  135.   global backgroundTileOffset,nrOfTiles
  136.   
  137.   set firstSprite = (backgroundTileOffset + 1)
  138.   set lastSprite = (backgroundTileOffset + nrOfTiles)
  139.   
  140.   repeat with currSprite = firstSprite to lastSprite
  141.     setSpriteVisibility currSprite FALSE    
  142.   end repeat
  143.   
  144. end
  145.  
  146.  
  147. -- -----------------------------------------------------------------------------
  148. -- handler showBackgroundTiles hides the tiled picture that gets revealed by answering
  149. -- questions
  150.  
  151. on showBackgroundTiles
  152.   global backgroundTileOffset,nrOfTiles
  153.   
  154.   set firstSprite = (backgroundTileOffset + 1)
  155.   set lastSprite = (backgroundTileOffset + nrOfTiles)
  156.   
  157.   repeat with currSprite = firstSprite to lastSprite
  158.     setSpriteVisibility currSprite TRUE    
  159.   end repeat
  160.   
  161. end
  162. -- -----------------------------------------------------------------------------
  163. -- handler makeRandomQuestionOrder creates nrOfTiles lines with nrOfQuestionsPerTile
  164. -- random unique numbers 
  165.  
  166. on makeRandomQuestionOrder
  167.   global nrOfQuestionsPerTile,nrOfTiles,questionNumbers,answers,questionIndex
  168.   global spriteNrOfFirstTileOffset
  169.   
  170.   -- determine which questions we need for game gameNr
  171.   set firstQuestionNr = getStartNr()
  172.   set lastQuestionNr  = getEndNr()
  173.   
  174.   set nrOfQuestions = nrOfQuestionsPerTile * nrOfTiles
  175.   set sourceList = getSourceList(firstQuestionNr,lastQuestionNr)
  176.   
  177.   --  empty the field that contains random questionnumbers
  178.   put "" into field "questionNumbers"
  179.   
  180.   repeat with tile = 1 to nrOfTiles
  181.     
  182.     set tileQuestions = []
  183.     set nrOfDraws = 0
  184.     
  185.     repeat with question = 1 to nrOfQuestionsPerTile
  186.       -- pick a random index used to draw a question
  187.       set nrOfQuestionsUsed = ((tile - 1) * nrOfQuestionsPerTile) + nrOfDraws
  188.       set index = random(nrOfQuestions - nrOfQuestionsUsed)
  189.       
  190.       -- draw the question number from the ordered list
  191.       set aQuestion = getAt(sourceList,index)
  192.       
  193.       -- add the drawn question to a string, separated by the itemdelimiter
  194.       append(tileQuestions,aQuestion)
  195.       
  196.       -- delete the randomly picked item so we don't draw it twice
  197.       deleteAt (sourceList,index)
  198.       set nrOfDraws = nrOfDraws + 1
  199.     end repeat
  200.     
  201.     -- add the pointer to the first question to be asked to the line of questionnumbers
  202.     append(tileQuestions,1)
  203.     
  204.     -- add the questions for this tile to the field
  205.     putListIntoLineOfField tileQuestions,tile,"questionNumbers"
  206.     
  207.   end repeat
  208.   
  209.   -- read the field with questionnumbers into a variable
  210.   set questionNumbers = field "questionNumbers"
  211.   
  212.   -- fill each tile on screen with a question and answers
  213.   repeat with currTile = 1 to nrOfTiles
  214.     set qSprite = 2 * currTile + spriteNrOfFirstTileOffset - 1
  215.     set aSprite = 2 * currTile + spriteNrOfFirstTileOffset
  216.     getQuestionForTile currTile,qSprite,aSprite
  217.   end repeat
  218.   
  219. end